/*
 *  $Id: SnakeBranches.cs 1051 2010-05-18 22:10:41Z thenn.erannor $
 *	This file is a part of Ragima CCG.
 *	(C) 2008 Ragima development group.
 *
 *	Licensed under the terms of the GNU GPL License version 2.
 *
 */

namespace Ragima.Cards001.Earth.Spells {
    public class SnakeBranches: SelfEnchantmentCard {
        public SnakeBranches(): base("001_e_s_snake_branches") {
            Level = CompleteLevel.ReadyForTest;
            Element = ElementType.Earth;
            Value = 100;
            AddManaCost(ElementType.Earth, 2);
        }

        protected override EnchantmentAffect CreateEnchantment() {
            return new SnakeBranchesAffect();
        }

        private class SnakeBranchesAffect: EnchantmentAffect<SnakeBranches> {
            private static readonly Languages.CardPhrase<SnakeBranches> Try = new Languages.CardPhrase<SnakeBranches>("try");

            public SnakeBranchesAffect() {
                Add(new Affects.OnHit(DoHit, AffectSummaryType.Enemy));
            }

            private static void DoHit(Creature hitter, AbstractObject target, int damage) {
                if (target is Player) return;
                int lands = 0;
                foreach (Land land in target.Owner.Lands)
                    if (land.Card.Element == ElementType.Earth)
                        lands++;
                lands = 7 - lands;
                int dice = Game.Current.GetDiceNextValue();
                bool success = dice >= lands;
                Game.Current.Log.Add(Try.Phrase, hitter, dice, Resources.Game.Success(success));
                if (success)
                    hitter.AddAffect(new Affects.Venom(1));
            }
        }
    }
}
